const util = require('../../utils/util.js');
const api = require('../../config/api.js');
// components/item/item.component.js
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    items: {
      type: Array, //必填，目前接受的类型包括：String, Number, Boolean, Object, Array, null（表示任意类型）
      value: ""
    },
    isPublic: {
      type: Boolean,
      value: false
    }
  },

  /**
   * 组件的初始数据
   */
  data: {

  },

  /**
   * 组件的方法列表
   */
  methods: {
    goDetail: function (event) {
      wx.navigateTo({
        url: '/pages/item-detail/item-detail',
      })
    },
    deleteRoom: function (event) {
      console.log(event)
      const id = event.currentTarget.dataset.id;
      var self = this;
      wx.showModal({
        title: '提示',
        content: '确定要删除这个房子',
        success: function (res) {
          if (res.confirm) {
            util.request(api.roomdeleteUrl, {id: id}, 'post').then(function (res) {
              if (res.errno === 0) {
                console.log("删除成功");
                self.triggerEvent('deleteEvent', true) 
              }
            })
          } else if (res.cancel) {
            console.log('用户点击取消')
          }
        }
      })
    },
    updateRoom: function () {
      wx.showToast({
        title: '该功能开发中……',
        duration: 2000
      })
    },
    generatQCode: function (e) {
      console.log(e)
      const room_name = e.currentTarget.dataset.name;
      const room_id = e.currentTarget.dataset.id;
      util.request(api.roomGeneratQRCodeUrl, { room_name: room_name, room_id: room_id}, 'post').then(function (res) {
        if (res.errno === 0) {
          console.log("生成成功");
        }
      })
    }
  }
})
